package com.wc.算法基础课.A第一讲基础算法.离散化.区间和;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;

/**
 * @Author congge
 * @Date 2024/2/28 10:57
 * @description https://www.acwing.com/problem/content/description/804/
 */
public class Main {
    static FastReader sc = new FastReader();
    static PrintWriter out = new PrintWriter(System.out);

    static int N = 300010;
    // 原始x,c
    static int[] index = new int[N];
    static int[] value = new int[N];

    // 离散化数组下标
    static int[] array = new int[N];
    // 离散化数组值
    static int[] a2v = new int[N];

    static int arrayLen = 0;

    // 前缀和数组
    static int[] s = new int[N];

    static int[] l = new int[N];
    static int[] r = new int[N];
    static int n, m, x, c;

    public static void main(String[] args) {
        n = sc.nextInt();
        m = sc.nextInt();
        for (int i = 1; i <= n; i++) {
            x = sc.nextInt();
            c = sc.nextInt();
            index[i] = x;
            value[i] = c;
            array[arrayLen++] = x;
        }

        // 输入
        for (int i = 1; i <= m; i++) {
            l[i] = sc.nextInt();
            r[i] = sc.nextInt();
            array[arrayLen++] = l[i];
            array[arrayLen++] = r[i];
        }

        Arrays.sort(array, 0, arrayLen);
        int len = 0;
        int preNum = Integer.MIN_VALUE;
        // 去重
        for (int i = 0; i < arrayLen; i++) {
            if (preNum != array[i]) {
                array[len++] = array[i];
                preNum = array[i];
            }
        }
        arrayLen = len;
        // 离散化赋值
        for (int i = 1; i <= n; i++) {
            x = find(index[i]);
            a2v[x] += value[i];
        }
        // 预处理前缀和
        for (int i = 1; i <= arrayLen; i++) {
            s[i] = s[i - 1] + a2v[i];
        }
        // 输出答案
        for (int i = 1; i <= m; i++) {
            int ll = find(l[i]);
            int rr = find(r[i]);
            out.println(s[rr] - s[ll - 1]);
        }
        out.flush();
    }

    // 坐标
    static int find(int x) {
        int l = 0, r = arrayLen;
        while (l < r) {
            int mid = l + r >> 1;
            if (array[mid] >= x) {
                r = mid;
            } else {
                l = mid + 1;
            }
        }
        // 坐标从1开始，方便前缀和
        return r + 1;
    }

    static class Pair implements Comparable<Pair> {
        int x, y;

        Pair(int x, int y) {
            this.x = x;
            this.y = y;
        }

        @Override
        public int compareTo(Pair o) {
            if (x == o.x) {
                return y - o.y;
            }
            return x - o.x;
        }
    }

}


class FastReader {
    StringTokenizer st;
    BufferedReader br;

    FastReader() {
        br = new BufferedReader(new InputStreamReader(System.in));
    }

    String next() {
        while (st == null || !st.hasMoreElements()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return st.nextToken();
    }

    int nextInt() {
        return Integer.parseInt(next());
    }

    String nextLine() {
        String s = "";
        try {
            s = br.readLine();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return s;
    }

    long nextLong() {
        return Long.parseLong(next());
    }

    double nextDouble() {
        return Double.parseDouble(next());
    }

    // 是否由下一个
    boolean hasNext() {
        while (st == null || !st.hasMoreTokens()) {
            try {
                String line = br.readLine();
                if (line == null)
                    return false;
                st = new StringTokenizer(line);
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return true;
    }
}